package com.weiaibenpao.demo.chislim.ui.activity.me;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.orhanobut.logger.Logger;
import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.base.BaseActivity;
import com.weiaibenpao.demo.chislim.bean.MeBean;
import com.weiaibenpao.demo.chislim.utils.Constant;

import butterknife.BindView;
import butterknife.OnClick;

public class GradeActivity extends BaseActivity {

    Intent intent;

    double pro;    //等级进度条进度
    double disPoor;    //还差的距离
    int grade;          //当前等级
    String nowGrade;           //当前等级
    String nextGrade;          //接下来的等级
    String restDis;
    @BindView(R.id.gradeNow)
    TextView gradeNow;
    @BindView(R.id.seekBar)
    SeekBar seekBar;
    @BindView(R.id.gradeNext)
    TextView gradeNext;
    @BindView(R.id.nextValue)
    TextView nextValue;
    @BindView(R.id.gradeText)
    TextView gradeText;
    @BindView(R.id.img_grade)
    ImageView imgGrade;

    private MeBean.GradeBean gradeBean;

    @Override
    public int setLayoutResourceID() {
        return R.layout.activity_grade;
    }

    @Override
    public void init(Bundle savedInstanceState) {
        intent = getIntent();

        pro = intent.getDoubleExtra("currentPro", 0);
        Logger.e("pro=="+pro);
//        disPoor = intent.getDoubleExtra("disPoor", 0);
//        grade = intent.getIntExtra("grade", 0);
        nowGrade = intent.getStringExtra("nowGrade");
        restDis = intent.getStringExtra("restDis");
        nextGrade = intent.getStringExtra("nextGrade");
        gradeBean = ((MeBean.GradeBean) intent.getSerializableExtra(Constant.CLASS_BEAN));
        immersionBar
//                .transparentBar()
                .statusBarDarkFont(false)
                // .statusBarColor(R.color.white)//状态栏颜色，不写默认透明色
                .fitsSystemWindows(false)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                .init();

        initView();
    }

    public static void startSelf(Context context, MeBean.GradeBean gradeBean, String nowGrade, String nextGrade, double currentPro,String restDis) {
        Intent intent = new Intent(context, GradeActivity.class);
        intent.putExtra(Constant.CLASS_BEAN, gradeBean);
        intent.putExtra("nowGrade", nowGrade);
        intent.putExtra("nextGrade", nextGrade);
        intent.putExtra("currentPro", currentPro);
        intent.putExtra("restDis",restDis);
        context.startActivity(intent);

    }

    public void initView() {
        Typeface typeFace = Typeface.createFromAsset(this.getAssets(), "fonts/Reducto Condensed SSi Condensed.ttf");
        gradeNow.setTypeface(typeFace);
        gradeNext.setTypeface(typeFace);

        gradeNow.setText(nowGrade);
        gradeNext.setText(nextGrade);
        seekBar.setProgress((int) (pro * 100));
       if (gradeBean!=null){
           nextValue.setText("距离升级还差：" + restDis + "公里");
           gradeText.setText("当前等级：" + gradeBean.getGradeName());
           Glide.with(this).load(gradeBean.getGradeImage()).into(imgGrade);
       }
//        seekBar.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View view, MotionEvent motionEvent) {
//                return true;
//            }
//        });

    }

    @OnClick(R.id.left_image)
    public void onViewClicked() {
        finish();
    }

}
